package com.loozb.thread2;

/**
 * 线程中断
 * @author 龙召碧
 * @create 2018-01-30 11:28
 **/
public class Interrupt {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread() {
            @Override
            public void run() {
                while(true) {
                    if(Thread.currentThread().isInterrupted()) {
                        System.out.println("已停止");
                        break;
                    }
                    System.out.println("正在运行");
                    Thread.yield();
                }
            }
        };
        t1.start();
        Thread.sleep(2000);
        t1.interrupt();
    }
}
